#!/bin/sh
################################################################################
# telnet
################################################################################
. /etc/rc.d/functions

start() {
    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/voip] Starting..."

    if [ "x${MM_VOIP_ENABLED}" = "xyes" ] ; then
        sipdaemonpid=`/bin/ps ax -o ppid,pid,args | grep '/usr/bin/sip-daemon.py' | grep -v grep`
        if [ -z "$sipdaemonpid" ] ; then
            /usr/bin/sip-daemon.sh &
            /usr/bin/logger -t minimyth -p "local0.info" "[init.d/voip] Starting Telephony SIP daemon..."
        fi
    fi

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/voip] Started with return code=0..."

    return 0
}

stop() {

if [ "x${MM_VOIP_ENABLED}" = "xyes" ] ; then
    sipdaemonpid=`/bin/ps ax -o ppid,pid,args | grep '/usr/bin/sip-daemon.py' | grep -v grep`
    if [ -n "$sipdaemonpid" ] ; then
        /usr/bin/killall sip-daemon.py
        /usr/bin/logger -t minimyth -p "local0.info" "[init.d/voip] Telephony SIP daemonN still alive. Killing it..."
    fi
fi

    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
